/*
 * Copyright 2010 - 2011, The PLDesktop Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */
#ifndef PLSIGNAL7_H
#define PLSIGNAL7_H

#include <kernel/signalslot/lang/PLSignalBase.h>
#include <kernel/signalslot/lang/PLConnection7.h>
#include <kernel/signalslot/lang/PLISignalBase7.h>
#define HASHTABLE_WITHOUT_PLOBJECT
#include <tools/PLHashTable.h>

namespace PLSDK {

    /**
     * Implement a signal with 7 parameters.
     */
    template < class arg0, class arg1, class arg2, class arg3, class arg4, class arg5, class arg6 >
    class PLSignal7 : public PLSignalBase {
    public:
        /**
         * Constructor.
         */
        PLSignal7() : PLSignalBase(), m_index(0) {}
        /**
         * Connect the signal.
         *
         * @param object The object to connect to.
         * @param pmemfun The function to connect to.
         * @return True if the connection was successfully.
         */
        template<class desttype>
        plbool connect(desttype *object, void(desttype::*pmemfun)(arg0, arg1, arg2, arg3, arg4, arg5, arg6)) {
            PLConnection7<desttype, arg0, arg1, arg2, arg3, arg4, arg5, arg6> *connection =
                new PLConnection7<desttype, arg0, arg1, arg2, arg3, arg4, arg5, arg6>(object, pmemfun);
            PLSignalBase::connect(dynamic_cast<PLObject *>(object), dynamic_cast<PLConnectionBase *>(connection),
                                  PLSignalTypesSignal7Params);
            m_signalsPrivate.insert(m_index, connection);
            connection->setSlotID(m_index);
            m_index++;
            return true;
        }
        /**
         * Emit the connections.
         *
         * @param argument0 The 0 argument.
         * @param argument1 The 1 argument.
         * @param argument2 The 2 argument.
         * @param argument3 The 3 argument.
         * @param argument4 The 4 argument.
         * @param argument5 The 5 argument.
         * @param argument6 The 6 argument.
         */
        void emit(arg0 argument0, arg1 argument1, arg2 argument2, arg3 argument3, arg4 argument4, arg5 argument5, arg6 argument6) {
            PLISignalBase7<arg0, arg1, arg2, arg3, arg4, arg5, arg6> *signal;
            PLHashTableEnumerator<PLUInteger64, PLISignalBase7<arg0, arg1, arg2, arg3, arg4, arg5, arg6> *> en =
                m_signalsPrivate.valueEnumerator();
            while(en.hasNext()) {
                signal = en.next();
                signal->emit(argument0, argument1, argument2, argument3, argument4, argument5, argument6);
            }
        }
        /**
         * Remove a connection from a signal with a id.
         *
         * @param slotID The slot id to remove.
         */
        void removeSignal(PLUInteger64 slotID) {
            PLISignalBase7<arg0, arg1, arg2, arg3, arg4, arg5, arg6> *data = m_signalsPrivate.remove(slotID);
            if(data != 0) {
                delete data;
                data = 0;
            }
        }
    private:
        PLHashTable<pluint64, PLISignalBase7<arg0, arg1, arg2, arg3, arg4, arg5, arg6> *> m_signalsPrivate;
        pluint64 m_index;
    };

}

#undef HASHTABLE_WITHOUT_PLOBJECT

#endif
